package com.athena.utils;

/**
 * @Author: xiaoxiang.zhang
 * @Description:Http协议工具类
 * @Date: Create in 11:50 下午 2020/3/25
 */
public class HttpProtocolUtil {

  /**
   * @return java.lang.String
   * @Author yuyz
   * @Description 封装返回结果为200时的请求头
   * @Date 11:52 下午 2020/3/25
   * @Param [dataLength]
   */
  public static String getHttpHeader200(long dataLength) {
    StringBuilder headerBuilder = new StringBuilder(180);
    headerBuilder.append("HTTP/1.1 200 OK");
    headerBuilder.append("\n");
    headerBuilder.append("Content-Type: text/html;charset=utf-8");
    headerBuilder.append("\n");
    headerBuilder.append("Content-Length: ").append(dataLength);
    headerBuilder.append("\n").append("\r\n");
    return headerBuilder.toString();
  }

  public static String getHttpHeader404() {
    String errorData = "<h1>404 NOT FOUND</h1>";
    StringBuilder headerBuilder = new StringBuilder(180);
    headerBuilder.append("HTTP/1.1 404 NOT FOUND");
    headerBuilder.append("\n");
    headerBuilder.append("Content-Type: text/html;charset=utf-8");
    headerBuilder.append("\n");
    headerBuilder.append("Content-Length: ").append(errorData.length());
    headerBuilder.append("\n").append("\r\n");
    headerBuilder.append(errorData);
    return headerBuilder.toString();
  }

  ;
}
